<template>
    <div class="main">
        <section>
            <el-form :inline="true" :model="formData" ref="form" class="demo-form-inline">
                <el-form-item label="保证金：" prop="value" :rules="commonRules.numberRule">
                    门店合伙人完成门店礼包销售 <el-input type="number" oninput="if(value.length>8)value=value.slice(0,8)" v-model="formData.value" size="small" placeholder="请输入" style="max-width: 130px"></el-input>
                    元后，允许返还保证金，否则不予以返还。
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" size="small" @click="save" :disabled="btnDisabled">保存</el-button>
                </el-form-item>
            </el-form>
        </section>
    </div>
</template>
<script>
  export default {
    name: 'bondSetting',
    data(){
      return {
        formData: {
          key: 'EARNEST_MONEY',
          value: ''
        },
        btnDisabled: false
      }
    },
    created(){
      this.fetchData();
    },
    methods: {
      fetchData(){
        this.request({
          url: '/bsnl-activity/system/setting/key/value/EARNEST_MONEY',
          method: 'get'
        }).then(({data}) => {
          this.formData.value = data || ''
        }).catch(err => {
          this.btnDisabled = false;
        });
      },
      save(){
        this.$refs.form.validate(valid => {
          if (!valid) {
            return false;
          }

          this.btnDisabled = true;
          this.request({
            url: '/bsnl-activity/system/setting/key/value/update',
            method: 'post',
            data: this.formData
          }).then(() => {
            this.btnDisabled = false;
            this.$message.success('保存成功');
          }).catch(err => {
            this.btnDisabled = false;
          });
        });
      }
    }
  }
</script>

